<?php

require_once 'Custom/Model/Db.php';

class Modules extends Custom_Model_Db
{
	/**
	 * The default table name 
	 */
    protected $_name 				= 	'modules';
    protected $_primary 			=	'id';
	
	public function getModules($isMenu=false)
	{		
		$datas = $this->getAllModules();		
		$array = array();	
		if(is_array($datas))foreach ($datas as $row){		
			if(empty($row['visible']))continue;
			if($isMenu && !$row['menu']){
				continue;
			}
			$array[$row['id']] = $row;			
		}
		return $array;
	}
	
	public function getAllModules()
	{		
		$where = $this->select()
		->order("order asc")
		->order("id asc");
		$rows = $this->fetchAll($where);
		$array = $rows->toArray();
		return $array;
	}
	
	public function getMenus()
	{		
		$datas = $this->getAllModules();		
		$array = array();	
		if(is_array($datas))foreach ($datas as $row){
			if(empty($row['menu']))continue;
			$array[] = $row;			
		}
		return $array;
	}
    
}
